package com.innovation.data.model;

import io.netty.channel.Channel;
import lombok.Data;
import lombok.EqualsAndHashCode;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Transient;
import com.innovation.exception.PatException;
import com.innovation.message.DataMsgProto.DataMsg;
import com.innovation.message.player.PlayerMsgProto.PlayerMsg;
import com.innovation.util.PropUtil;

@Entity(noClassnameStored = true)
@EqualsAndHashCode(callSuper=false)
@Data
public class Player extends BaseModel{
	@Id
	private int id; //玩家id
	private String openId; //平台id
	private String name; //玩家名称
	private int level; //玩家等级
	private int exp; //玩家当前经验
	private int createTime; //账号创建时间
	private int loginTime; //当前登录时间
	private int lastLoginTime; //上次登录时间
	private int money; //玩家游戏币
	private int gold; //玩家充值人民币
	private int sysGold; //玩家系统产出的人民币
	private int battlePoint; //战斗点
	private int resumeTime; //恢复战斗点的时间(单位:秒)
	private int room; //负重(格子数)
	private int maxFightHeroNum = 1; //默认开始只有一个宠物能出战,剩余的需要解锁格子,最多初始可以上场4个宠物
	private int guideStep = 0;//新手引导步骤
	
	private int pvpScore = 0; //PVP战绩
	private int pvpWinTimes = 0; //PVP胜利总次数
	private int pvpLoseTimes = 0; //PVP失败总次数
	
	@Transient
	private int accessTime; //访问时间
	@Transient
	private Channel channel; //客户端连接
	@Transient
	private DataMsg.Builder dataMsg = DataMsg.newBuilder(); //服务器端推送数据(推送的数据需要在客户端缓存)
	@Transient
	private int heartBeatTime = 0; //上次心跳时间
	
	@Transient
	private int dataLoadSign = ModelData.DATA_EMPTY;//已加载的数据标示
//	@Transient
//	private PlayerHero playerHero = null; //玩家英雄
//	@Transient
//	private PlayerItem playerItem = null; //玩家道具数据
//	@Transient
//	private PlayerPVE playerPVE = null; //玩家pve数据
//	@Transient
//	private PlayerDailyData playerDailyData = null; //玩家每日重置数据
//	@Transient
//	private PlayerMessage playerMessage = null; //玩家消息
//	@Transient
//	private PlayerMission playerMission = null; //玩家任务
	@Transient
	private int sessionId = 0; //下一个请求的session标示
	
	public void write2Proto(PlayerMsg.Builder builder) throws PatException{
		PropUtil.copyProperties(builder, this, PlayerMsg.Builder.getDescriptor());
		builder.setGold(this.getGold() + this.getSysGold());
	}
	
	/**
	 * 添加已加载的数据
	 * @param data
	 */
	public void addDataLoadSign(int data) {
		dataLoadSign = dataLoadSign | data;
	}

	/**
	 * 检查数据是否已经加载
	 * @param data
	 * @return
	 */
	public boolean checkDataLoad(int data) {
		return (dataLoadSign & data) == data;
	}
}
